import {rankingStore} from '../../store/index'
import {getSongDetail} from '../../service/api_music'

// components/detail-songs/index.js
Page({


  data: {
    type:"",
    ranking:"",
    songInfo:{}
  },

  onLoad:function(options){
    const type = options.type
    this.setData({type})
    if(type === "menu"){
      const id = options.id
      // console.log(id)
      getSongDetail(id).then(res=>{
       this.setData({songInfo:res.playlist})
      })
    }else if(type === "rank"){
       const ranking = options.ranking
    // console.log(ranking);
      this.setData({ranking})
      rankingStore.onState(ranking,this.getRankingDataHanlder)
    }
   
  },
  onUnload:function(){
   if(this.data.ranking) {
    rankingStore.offState(this.data.ranking,this.getRankingDataHanlder)
   }
  },
  
  getRankingDataHanlder:function(res){
    // console.log(res);
    this.setData({songInfo:res})
  }
})
